package com.example.echoewish.repository;

import com.example.echoewish.repository.network.PostServiceNetwork;
import com.example.echoewish.pojo.Post;
import com.example.echoewish.util.LogUtil;

import java.io.File;

import retrofit2.Callback;

public class PostMessageRepository {
    private static  final PostMessageRepository instance=new PostMessageRepository();

    public static PostMessageRepository getInstance()
    {
        return instance;
    }

    public void publishPost(File image, Post post, Callback callback)
    {
        try
        {
            PostServiceNetwork.publishPost(image,post,callback);
            new LogUtil().d(LogUtil.GET_DATA_TAG,"发布帖子接口调用时 发起网络请求成功");
        }
        catch (Exception e)
        {
            new LogUtil().d(LogUtil.GET_DATA_TAG,"发布帖子接口调用时 发起网络请求失败");
        }
    }

    public void deletePost(int userId, Callback callback)
    {
        try {
            PostServiceNetwork.deletePost(userId,callback);
            new LogUtil().d(LogUtil.GET_DATA_TAG,"删除帖子接口调用时 发起网络请求成功");
        }
        catch (Exception e)
        {
            new LogUtil().d(LogUtil.GET_DATA_TAG,"删除帖子接口调用时 发起网络请求失败");
        }
    }

    public void queryPost(int postId,Callback callback)
    {
        try {
            PostServiceNetwork.queryPost(postId,callback);
            new LogUtil().d(LogUtil.GET_DATA_TAG,"获取帖子接口调用时 发起网络请求成功");
        }
        catch (Exception e)
        {
            new LogUtil().d(LogUtil.GET_DATA_TAG,"获取帖子接口调用时 发起网络请求失败");
        }
    }

    public void queryDetailPost(int postId,Callback callback)
    {
        try {
            PostServiceNetwork.queryDetailPost(postId,callback);
            new LogUtil().d(LogUtil.GET_DATA_TAG,"获取帖子详细信息显示接口调用时 发起网络请求成功");
        }
        catch (Exception e)
        {
            new LogUtil().d(LogUtil.GET_DATA_TAG,"获取帖子详细信息显示接口调用时 发起网络请求失败");
        }
    }

    public void queryPartPost(int start,int end,Callback callback)
    {
        try {
            PostServiceNetwork.queryPartPost(start,end,callback);
            new LogUtil().d(LogUtil.GET_DATA_TAG,"获取帖子接口调用时 发起网络请求成功");
        }
        catch (Exception e)
        {
            new LogUtil().d(LogUtil.GET_DATA_TAG,"获取帖子接口调用时 发起网络请求失败");
        }
    }

    public void queryPartPostByZone(int start,int end,String zone,Callback callback)
    {
        try {
            PostServiceNetwork.queryPartPostByZone(start,end,zone,callback);
            new LogUtil().d(LogUtil.GET_DATA_TAG,"获取帖子接口调用时 发起网络请求成功");
        }
        catch (Exception e)
        {
            new LogUtil().d(LogUtil.GET_DATA_TAG,"获取帖子接口调用时 发起网络请求失败");
        }
    }

    public void queryPartPostByKeyWord(String keyword,Callback callback)
    {
        try {
            PostServiceNetwork.queryPartPostByKeyWord(keyword,callback);
            new LogUtil().d(LogUtil.GET_DATA_TAG,"获取帖子接口调用时 发起网络请求成功");
        }
        catch (Exception e)
        {
            new LogUtil().d(LogUtil.GET_DATA_TAG,"获取帖子接口调用时 发起网络请求失败");
        }
    }

    public void  queryPartPostByZoneAndKeyWord(String zone,String keyword,Callback callback)
    {
        try {
            PostServiceNetwork.queryPartPostByZoneAndKeyWord(zone,keyword,callback);
            new LogUtil().d(LogUtil.GET_DATA_TAG,"获取帖子接口调用时 发起网络请求成功");
        }
        catch (Exception e)
        {
            new LogUtil().d(LogUtil.GET_DATA_TAG,"获取帖子接口调用时 发起网络请求失败");
        }
    }

    public void queryMyPublishPostByUserId(int userId,Callback callback)
    {
        try {
            PostServiceNetwork.queryMyPublishPostByUserId(userId,callback);
            new LogUtil().d(LogUtil.GET_DATA_TAG,"获取我的帖子接口调用时 发起网络请求成功");
        }
        catch (Exception e)
        {
            new LogUtil().d(LogUtil.GET_DATA_TAG,"获取我的帖子接口调用时 发起网络请求失败");
        }
    }

    public void getHotSearch(int num,Callback callback)
    {
        try {
            PostServiceNetwork.getHotSearch(num,callback);
            new LogUtil().d(LogUtil.GET_DATA_TAG,"获取热搜接口调用时 发起网络请求成功");
        }
        catch (Exception e)
        {
            new LogUtil().d(LogUtil.GET_DATA_TAG,"获取热搜接口调用时 发起网络请求失败");
        }
    }
}
